﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Freetime.GlobalHandling;
using Freetime.Authentication;
using Freetime.Base.Data;
using Freetime.Base.Framework;
using Freetime.Configuration;
using Freetime.Base.Business.Implementable;

namespace Freetime.Base.Business
{
    public abstract class BaseLogic : ILogic
    {
        private DataSession m_dataSession = null;
        private FreetimeUser m_freetimeUser = null;

        protected virtual DataSession DataSession
        {
            get
            {
                if (m_dataSession == null)
                    m_dataSession = (DataSession) ConfigurationManager.GetDefaultSession();
                return m_dataSession;
            }
        }

        public virtual FreetimeUser CurrentUser
        {
            get
            {
                return m_freetimeUser;
            }            
        }

        public BaseLogic(FreetimeUser user)
        {
            m_freetimeUser = user;
        }

        public BaseLogic()
        {             
        }

        protected bool HasEvent(string eventName)
        {
            return GlobalEventDispatcher.HasEvent(eventName);
        }

        protected void RaiseEvent(string eventName)
        {
            GlobalEventDispatcher.RaiseEvent(eventName, this, null);
        }

        protected void RaiseEvent(string eventName, EventArgs args)
        {
            GlobalEventDispatcher.RaiseEvent(eventName, this, args);
        }

        protected void RaiseEvent(string eventName, object sender, EventArgs args)
        {
            GlobalEventDispatcher.RaiseEvent(eventName, sender, args);
        }
    }
}
